using System;
using BoxBinary.AspectCache.Core.PolicyDefinition;

namespace BoxBinary.AspectCache.Core.Broadcast
{
    /// <summary>
    /// Encapsultates an <see cref="IPolicyBoundCachePackage"/> together with a date stamp and an event reason (<see cref="BroadcastEventReason"/>). 
    /// Used for serializing a cache entry to disk with extra information in order to notify several disparate machines of a cache change.
    /// </summary>
    [Serializable]
    public class BroadcastEvent
    {
        #region Constructors

        /// <summary>
        /// Creates a new instance of a BroadcastEvent from the given <see cref="BroadcastEventReason"/>
        /// and wrapping the given <see cref="IPolicyBoundCachePackage"/>
        /// </summary>
        /// <param name="broadcastEventReason">Reason for the event</param>
        /// <param name="package">Cache item to be broadcast</param>
        public BroadcastEvent(BroadcastEventReason broadcastEventReason, IPolicyBoundCachePackage package)
        {
            Reason = broadcastEventReason;
            Package = package;
        }

        #endregion

        #region Instance fields

        private DateTime _dateStamp = DateTime.Now;

        #endregion

        #region Public properties

        /// <summary>
        /// Describes the reason that the event was raised.
        /// </summary>
        public BroadcastEventReason Reason { get; set; }

        /// <summary>
        /// The <see cref="IPolicyBoundCachePackage"/> representing the actual cache entry.
        /// </summary>
        public IPolicyBoundCachePackage Package { get; set; }

        /// <summary>
        /// The <see cref="DateTime"/> that the event was raised.
        /// </summary>
        public DateTime DateStamp
        {
            get { return _dateStamp; }
            set { _dateStamp = value; }
        }

        #endregion
    }
}